$(function() {

	question_list.initial();
});

var question_list = {
	initial : function initial() {
		this.bindChangeSearchParam();
		this.bindDelete();
	},
	
	bindChangeSearchParam : function bindChangeSearchParam(){
		
		$(".pagination li a").click(function(){
			var pageId = $(this).data("id");
			if(pageId==null||pageId=="")return false;
			var genrateParamOld = question_list.genrateParamOld();
			genrateParamOld.page = pageId;
			question_list.redirectUrl(genrateParamOld);
			
		});
	},
	
	genrateParamOld :function genrateParamOld(){
		
		var page = 1;
		var data = new Object();
		data.page = page;
		
		return data;
	},

	redirectUrl : function(newparam) {
		var paramurl = newparam.page;

		document.location.href = document.getElementsByTagName('base')[0].href
				+ util.getCurrentRole() + '/training/training-list?page=' + paramurl;
	},
	
	
	bindDelete : function bindDelete(){
		$(".delete-training").click(function(){
            if (confirm("确定删除该培训课程吗？")) {

                $.ajax({
                    headers: {
                        'Accept': 'application/json',
                        'Content-Type': 'application/json'
                    },
                    type: "GET",
                    url: $(this).data("role")+"/common/training-delete-" + $(this).data("id"),
                    success: function (message, tst, jqXHR) {
                        if (!util.checkSessionOut(jqXHR))
                            return false;
                        if (message.result == "success") {
                            util.success("删除成功", function () {
                                window.location.reload();
                            });
                        } else {
                            util.error("操作失败:" + message.result);
                        }

                    }
                });

            }


			
		});
	}
};